#国控站点排名情况
library(tidyverse)
library(lubridate)

conn <- src_sqlite("~/Documents/rockontrol/合肥项目数据/合肥市项目.db")

begin <- "2019-07-01"
end <- "2019-07-31"

town <-  "包河区"

dataset <- tbl(conn,"日数据") %>%
  inner_join(tbl(conn,"站点信息"),by  =c("站点名称"="站点")) %>%
  filter(类型 == "国控站",日期>= begin,日期<= end,区县 ==town)  %>% collect()

dataset %>% select (站点名称,等级,首要污染物,AQI) %>% mutate(首要污染物 = ifelse(等级=="优","无",首要污染物))%>%
  ggplot(aes(x = reorder(等级,desc(AQI)),group = 首要污染物,fill = 首要污染物))+ 
  geom_bar(position = "stack",width = 0.5)+
  facet_wrap(站点名称 ~.,scales = "free") +
  labs(x="",y="")+
  theme_bw()+
  theme(  plot.title =   element_text(hjust = 0.5),
        axis.text.x=element_text(size = 15,vjust = 0.5),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size = 15),
        strip.text = element_text(size= 15),legend.text.align = 0,legend.title = element_blank(),
        legend.text = element_text(size = 15)) 


DBI::dbDisconnect(conn$con)
